﻿/*****************************************************************//**
 * \file   SurgicalRobotCommunication.h
 * \brief  负责上层、算法层、底层通信类
 *
 * \author Administrator
 * \date   July 2021
 * \modify by Administrator
 * \date   July 2021

 *********************************************************************/
#pragma once

#include <vector>
#include <QCoreApplication>
#include <QDir>
#include <iostream>
#include <fstream>
#include <string>
#include <QThread>
#include <sys/stat.h>
 //中间层会用到各个机械臂和算法接口，所以包含用到的相应头文件
#include "SurgicalRobotCommon.h"
#include "../hardware_interface/Robot/RobotControlInterface.h"
#include "../hardware_interface/EndTool/EndToolInterface.h"
#include "../hardware_interface/HapticDevice/HapticDeviceControl.h"
#include "../Algirithm/genera/GeneraAlgirithm.h"

#include <fstream>

class  SurgicalRobotCommunication : public QObject
{
	Q_OBJECT

public:

	SurgicalRobotCommunication();

	~SurgicalRobotCommunication();

public:
	bool bAppExit = false;
    std::string paramsPath = QDir::toNativeSeparators(qApp->applicationDirPath() + "/../experiment_data").toStdString();
    std::string robotArmConfigFile = "/robotConfigParam.txt";

    RobotControlInterface* robotControl[MaxRobotNum];
	EndToolInterface* endTool[MaxRobotNum];
	HapticDeviceControl HDControl[2];
    static void setThreadAffinity(int cpu);


public:
	//Algirithm
	GeneraAlgirithm* pGeneraAlgirithm = new GeneraAlgirithm();

private:
	static SurgicalRobotCommunication* m_pInstance;

public:

    static SurgicalRobotCommunication* GetInstance()
	{
		if (m_pInstance == NULL) {
			m_pInstance = new SurgicalRobotCommunication();
		}
		return m_pInstance;
	}

public:
	//上层UI调用
	void InitConfigParam();
    bool SaveRobotConfig();
	void ReadConfigParam();
	bool initRobot(int robotNumber, const char* ipAddr);
	bool initEndTool(int robotNumber);

public:
	//experimental data
	std::fstream  read_robot_experimrnt;


public:
	//public slots:
		//线程持续读取机械臂和末端器械状态
	void threadGetRobotStatus();
    void run_code();
private:
	void getEndToolMatrix(int robotNumber);
};
